from django.shortcuts import render
import requests
import json

# Create your views here.
from django.views import View

from utils.seacher import search, user_detail

text = ''
class SearchView(View):
    """搜索页面"""
    def get(self, request):
        # 获取数据
        text = request.GET.get('text')
        # 获取相关歌曲
        search_lists = search(text)
        singer = search_lists[0]['singer']
        # 获取歌手信息
        singer_detail_list = user_detail(singer)
        print(singer_detail_list[0]['name'], '--=-=-=-=')
        context = {
            'lists': search_lists,
            'singer_detail': singer_detail_list,
            'singer': singer,
        }
        # print(context)
        return render(request, 'search.html', context)

